home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / PInterfaces / fenv.p < prev    next >
Encoding:
Text File  |  1997-08-12  |  11.0 KB  |  270 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        fenv.p
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1987-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. }
  18. {$IFC UNDEFINED UsingIncludes}
  19. {$SETC UsingIncludes := 0}
  20. {$ENDC}
  21.  
  22. {$IFC NOT UsingIncludes}
  23.  UNIT fenv;
  24.  INTERFACE
  25. {$ENDC}
  26.  
  27. {$IFC UNDEFINED __FENV__}
  28. {$SETC __FENV__ := 1}
  29.  
  30. {$I+}
  31. {$SETC fenvIncludes := UsingIncludes}
  32. {$SETC UsingIncludes := 1}
  33.  
  34. {$IFC UNDEFINED __CONDITIONALMACROS__}
  35. {$I ConditionalMacros.p}
  36. {$ENDC}
  37.  
  38.  
  39. {$PUSH}
  40. {$ALIGN MAC68K}
  41. {$LibExport+}
  42.  
  43. {
  44.         A collection of functions designed to provide access to the floating
  45.         point environment for numerical programming. It is modeled after
  46.         the floating-point requirements in C9X.
  47.         
  48.         The file <fenv.h> declares many functions in support of numerical
  49.         programming.  It provides a set of environmental controls similar to
  50.         the ones found in <SANE.h>.  Programs that test flags or run under
  51.         non-default modes must do so under the effect of an enabling
  52.         "fenv_access" pragma.
  53. }
  54.  
  55. {$IFC TARGET_CPU_PPC }
  56. {    The typedef fenv_t is a type for representing the entire floating-point
  57.       environment in a single object.                                         }
  58.  
  59. TYPE
  60.     fenv_t                                = LONGINT;
  61. {    The typedef fexcept_t is a type for representing the floating-point
  62.       exception flag state collectively.                                      }
  63.     fexcept_t                            = LONGINT;
  64. {    Definitions of floating-point exception macros                          }
  65.  
  66. CONST
  67.     FE_INEXACT                    = $02000000;
  68.     FE_DIVBYZERO                = $04000000;
  69.     FE_UNDERFLOW                = $08000000;
  70.     FE_OVERFLOW                    = $10000000;
  71.     FE_INVALID                    = $20000000;
  72.  
  73. {    Definitions of rounding direction macros                                }
  74.     FE_TONEAREST                = $00000000;
  75.     FE_TOWARDZERO                = $00000001;
  76.     FE_UPWARD                    = $00000002;
  77.     FE_DOWNWARD                    = $00000003;
  78.  
  79. {$ENDC}  {TARGET_CPU_PPC}
  80.  
  81. {$IFC TARGET_CPU_68K }
  82. {$IFC TARGET_RT_MAC_68881 }
  83.  
  84. TYPE
  85.     fexcept_t                            = LONGINT;
  86.     fenv_tPtr = ^fenv_t;
  87.     fenv_t = RECORD
  88.         FPCR:                    LONGINT;
  89.         FPSR:                    LONGINT;
  90.     END;
  91.  
  92.  
  93. CONST
  94.     FE_INEXACT                    = $00000008;                    {  ((long)(8))    }
  95.     FE_DIVBYZERO                = $00000010;                    {  ((long)(16))   }
  96.     FE_UNDERFLOW                = $00000020;                    {  ((long)(32))   }
  97.     FE_OVERFLOW                    = $00000040;                    {  ((long)(64))   }
  98.     FE_INVALID                    = $00000080;                    {  ((long)(128))  }
  99.  
  100. {$ELSEC}
  101.  
  102. TYPE
  103.     fexcept_t                            = INTEGER;
  104.     fenv_t                                = INTEGER;
  105.  
  106. CONST
  107.     FE_INVALID                    = $0001;                        {  ((short)(1))   }
  108.     FE_UNDERFLOW                = $0002;                        {  ((short)(2))   }
  109.     FE_OVERFLOW                    = $0004;                        {  ((short)(4))   }
  110.     FE_DIVBYZERO                = $0008;                        {  ((short)(8))   }
  111.     FE_INEXACT                    = $0010;                        {  ((short)(16))  }
  112.  
  113. {$ENDC}
  114.     FE_TONEAREST                = $0000;                        {  ((short)(0))   }
  115.     FE_UPWARD                    = $0001;                        {  ((short)(1))   }
  116.     FE_DOWNWARD                    = $0002;                        {  ((short)(2))   }
  117.     FE_TOWARDZERO                = $0003;                        {  ((short)(3))   }
  118.  
  119. {    Definitions of rounding precision macros  (68K only)                    }
  120.     FE_LDBLPREC                    = $0000;                        {  ((short)(0))   }
  121.     FE_DBLPREC                    = $0001;                        {  ((short)(1))   }
  122.     FE_FLTPREC                    = $0002;                        {  ((short)(2))   }
  123.  
  124. {$ENDC}  {TARGET_CPU_68K}
  125.  
  126. {    The bitwise OR of all exception macros                                  }
  127.  
  128. CONST
  129.     FE_ALL_EXCEPT = ( FE_INEXACT + FE_DIVBYZERO + FE_UNDERFLOW + FE_OVERFLOW + FE_INVALID );
  130.  
  131. {    Definition of pointer to IEEE default environment object               }
  132. VAR
  133.  {$PUSH}
  134.  {$J+}
  135.  _FE_DFL_ENV: fenv_t;               { default environment object        }
  136.  {$POP}
  137.  
  138. {******************************************************************************
  139. *     The following functions provide access to the exception flags.  The      *
  140. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  141. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  142. ******************************************************************************}
  143. {******************************************************************************
  144. *     The function "feclearexcept" clears the supported exceptions represented *
  145. *     by its argument.                                                         *
  146. ******************************************************************************}
  147. PROCEDURE feclearexcept(excepts: LONGINT); C;
  148.  
  149.  
  150. {******************************************************************************
  151. *    The function "fegetexcept" stores a representation of the exception       *
  152. *     flags indicated by the argument "excepts" through the pointer argument   *
  153. *     "flagp".                                                                 *
  154. ******************************************************************************}
  155. PROCEDURE fegetexcept(VAR flagp: fexcept_t; excepts: LONGINT); C;
  156.  
  157.  
  158. {******************************************************************************
  159. *     The function "feraiseexcept" raises the supported exceptions             *
  160. *     represented by its argument.                                             *
  161. ******************************************************************************}
  162. PROCEDURE feraiseexcept(excepts: LONGINT); C;
  163.  
  164.  
  165. {******************************************************************************
  166. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  167. *     by the int argument "excepts" according to the representation in the     *
  168. *     object pointed to by the pointer argument "flagp".  The value of         *
  169. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  170. *     This function does not raise exceptions; it just sets the state of       *
  171. *     the flags.                                                               *
  172. ******************************************************************************}
  173. PROCEDURE fesetexcept({CONST}VAR flagp: fexcept_t; excepts: LONGINT); C;
  174.  
  175.  
  176. {******************************************************************************
  177. *     The function "fetestexcept" determines which of the specified subset of  *
  178. *     the exception flags are currently set.  The argument "excepts" specifies *
  179. *     the exception flags to be queried as a bitwise OR of the exception       *
  180. *     macros.  This function returns the bitwise OR of the exception macros    *
  181. *     corresponding to the currently set exceptions included in "excepts".     *
  182. ******************************************************************************}
  183. FUNCTION fetestexcept(excepts: LONGINT): LONGINT; C;
  184.  
  185.  
  186. {******************************************************************************
  187. *     The following functions provide control of rounding direction modes.     *
  188. ******************************************************************************}
  189. {******************************************************************************
  190. *     The function "fegetround" returns the value of the rounding direction    *
  191. *     macro which represents the current rounding direction.                   *
  192. ******************************************************************************}
  193. FUNCTION fegetround: LONGINT; C;
  194.  
  195.  
  196. {******************************************************************************
  197. *     The function "fesetround" establishes the rounding direction represented *
  198. *     by its argument.  It returns nonzero if and only if the argument matches *
  199. *     a rounding direction macro.  If not, the rounding direction is not       *
  200. *     changed.                                                                 *
  201. ******************************************************************************}
  202. FUNCTION fesetround(round: LONGINT): LONGINT; C;
  203.  
  204.  
  205. {******************************************************************************
  206. *    The following functions manage the floating-point environment, exception  *
  207. *    flags and dynamic modes, as one entity.                                   *
  208. ******************************************************************************}
  209. {******************************************************************************
  210. *     The function "fegetenv" stores the current floating-point environment    *
  211. *     in the object pointed to by its pointer argument "envp".                 *
  212. ******************************************************************************}
  213. PROCEDURE fegetenv(VAR envp: fenv_t); C;
  214.  
  215.  
  216. {******************************************************************************
  217. *     The function "feholdexcept" saves the current environment in the object  *
  218. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  219. *     and clears floating-point exception enables.  This function supersedes   *
  220. *     the SANE function "procentry", but it does not change the current        *
  221. *     rounding direction mode.                                                 *
  222. ******************************************************************************}
  223. FUNCTION feholdexcept(VAR envp: fenv_t): LONGINT; C;
  224.  
  225.  
  226. {******************************************************************************
  227. *     The function "fesetenv" installs the floating-point environment          *
  228. *     environment represented by the object pointed to by its argument         *
  229. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  230. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  231. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  232. ******************************************************************************}
  233. PROCEDURE fesetenv({CONST}VAR envp: fenv_t); C;
  234.  
  235.  
  236. {******************************************************************************
  237. *     The function "feupdateenv" saves the current exceptions into its         *
  238. *     automatic storage, installs the environment represented through its      *
  239. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  240. *     This function, which supersedes the SANE function "procexit", can be     *
  241. *     used in conjunction with "feholdexcept" to write routines which hide     *
  242. *     spurious exceptions from their callers.                                  *
  243. ******************************************************************************}
  244. PROCEDURE feupdateenv({CONST}VAR envp: fenv_t); C;
  245.  
  246.  
  247. {$IFC TARGET_CPU_68K }
  248. {******************************************************************************
  249. *     The following functions provide control of rounding precision.           *
  250. *     Because the PowerPC does not provide this capability, these functions    *  
  251. *     are available only for the 68K Macintosh.  Rounding precision values     *
  252. *     are defined by the rounding precision macros.  These functions are       *
  253. *     equivalent to the SANE functions getprecision and setprecision.          *
  254. ******************************************************************************}
  255. FUNCTION fegetprec: LONGINT; C;
  256. FUNCTION fesetprec(precision: LONGINT): LONGINT; C;
  257. {$ENDC}  {TARGET_CPU_68K}
  258.  
  259.  
  260. {$ALIGN RESET}
  261. {$POP}
  262.  
  263. {$SETC UsingIncludes := fenvIncludes}
  264.  
  265. {$ENDC} {__FENV__}
  266.  
  267. {$IFC NOT UsingIncludes}
  268.  END.
  269. {$ENDC}
  270.